//
//  GiftView.swift
//  FirstSwiftProduct
//
//  Created by 知合金服-Mini on 2017/11/28.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

protocol giftImageSelectDelegate :class{
    func SelectDelegate(index:Int)
}


class GiftView: UIView {
    
    
    weak var delegate : giftImageSelectDelegate?
    
    let FTag = 88888
    
    private let count = 6
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let FWidth = SCREEN_WIDTH / CGFloat(count)
        let FHeight = SCREEN_WIDTH / CGFloat(count)
        
        let imageNameArr = ["talk_public_40x40_","talk_private_40x40_","talk_sendgift_40x40_","talk_rank_40x40_","talk_share_40x40_","talk_close_40x40_"]
        
        
        for i in 0...(imageNameArr.count-1){
            let button = UIButton.init(type: UIButtonType.custom)
            button.tag = FTag + i
            button.frame = CGRect(x: CGFloat(i) * FWidth, y: 0, width: FWidth, height: FHeight)
            button.addTarget(self, action: #selector(selectD(sender:)), for: UIControlEvents.touchUpInside)
            button.setImage(UIImage.init(named: imageNameArr[i]), for: UIControlState.normal)
            addSubview(button)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func selectD(sender:UIButton) -> Void {
        print("sender")
        let Findex = sender.tag - FTag
        
        delegate?.SelectDelegate(index: Findex)
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
